<template>
  <div class="colloca">
    <div class="label-name">精品推荐</div>

    <div class="colloca-all" :style="{ height: colHeight }">
      <div
        class="colloca-tiem"
        v-for="(item, index) in collocaList"
        :key="index"
      >
        <div>
          <a :href="hrefs + collocaList[index].fid"
            ><img :src="collocaList[index].fimg" alt=""
          /></a>
        </div>

        <div class="colloca-line">
          <div>
            <div class="colloca-name">
              <a :href="hrefs + collocaList[index].fid">{{
                collocaList[index].fname
              }}</a>
            </div>
            <div class="colloca-nei">
              <a :href="hrefs + collocaList[index].fid">{{
                collocaList[index].fcontent
              }}</a>
            </div>
            <div class="colloca-bottom">
              <div>浏览量 : {{ collocaList[index].fvisits }}</div>

              <div class="tag_2uAvO">
                <a :href="hrefs + collocaList[index].fid">{{
                  collocaList[index].ftName
                }}</a>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { request } from "../../network/request";

export default {
  name: "Collocation2",
  data() {
    return {
      fullWidth: document.documentElement.clientWidth,
      colHeight: "2.3rem",
      collocaList: "",
      hrefs: "/showfood?fid=",
    };
  },
  created() {
    this.handleResize();
    request({
      url: "/firstpage/queryRecommendation",
    })
      .then((res) => {
        this.collocaList = res.data.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
  beforeDestroy: function () {
    window.removeEventListener("resize", this.handleResize);
  },
  methods: {
    //获取当前页面高度，并改变colHeight的值
    handleResize() {
      this.fullWidth = document.documentElement.clientWidth;
      if (this.fullWidth <= 1246) {
        this.colHeight = "4.6rem";
      } else {
        this.colHeight = "2.3rem";
      }

      console.log(this.fullWidth);
    },
  },
};
</script>

<style>
.colloca {
  width: 85%;
  margin: 0 auto;
  margin-top: 0.4rem;
  margin-bottom: 0.15rem;
}

.label-name {
  font-size: 0.15rem;
  margin-bottom: 0.15rem;
}

.colloca-all {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.colloca-tiem {
  font-size: 0.12rem;
  border-radius: 0.07rem;
  width: 1.75rem;
  margin-top: 0.04rem;
  margin-bottom: 0.4rem;
  cursor: pointer;
  transition: all 0.5s;
}

.colloca-tiem:hover {
  box-shadow: 10px 10px 10px -3px #adacac;
}

.colloca-tiem:hover .colloca-nei {
  padding-top: 0.15rem;
  height: 0.15rem;
}

.colloca-tiem a {
  text-decoration: none;
  color: black;
  letter-spacing: 0.01rem;
}

.colloca-tiem img {
  width: 1.75rem;
  height: 0.8rem;
  border-radius: 0.07rem 0.07rem 0 0;
}

.colloca-name {
  width: 1.65rem;
  margin: 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 0.2rem;
}

.colloca-line {
  border: 1px solid rgb(216, 212, 208);
  margin-top: -0.1rem;
  border-radius: 0 0 0.08rem 0.08rem;
}

.colloca-nei {
  width: 1.65rem;
  font-size: 0.09rem;
  height: 0;
  overflow: hidden;
  margin: 0 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.5s;
}

.colloca-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 0.2rem;
  font-size: 0.12rem;
}

.colloca-bottom :nth-child(1) {
  margin-left: 0.1rem;
  margin-bottom: 0.15rem;
  font-size: 0.09rem;
}

.colloca-bottom :nth-child(2) a {
  color: rgb(197, 197, 197);
}

.colloca-bottom :nth-child(2) a:hover {
  color: rgb(125, 214, 250);
}

.tag_2uAvO {
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-left: 0 none;
  padding: 0 8px 0 6px;
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
  margin: 0 12px;
  line-height: 15px;
  height: 22px;
  position: relative;
  box-sizing: border-box;
  border-color: rgba(0, 0, 0, 0.1);
}

.tag_2uAvO:before {
  content: "";
  display: block;
  position: absolute;
  width: 12px;
  height: 12px;
  border-left: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  border-color: inherit;
  top: 50%;
  transform: translateY(-50%) rotate(50deg) skew(10deg);
  left: -7px;
  box-sizing: border-box;
  border-bottom-left-radius: 4px;
}
</style>